#!/bin/bash

while true; do
	printf "input a line: "
	read -r LINE

	if [[ $LINE = "" ]]; then
		break
	fi

	if [[ $LINE =~ [[:space:]]*(a)?b ]]; then
		echo Match:
		echo "${BASH_REMATCH[0]}"
		echo "${BASH_REMATCH[1]}"
	else
		echo Failed
	fi
done
